import Vue from 'vue';
import App from './App';
import router from './router';
import store from './store';
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';
import vuescroll from 'vuescroll'; //引入vuescroll
import 'vuescroll/dist/vuescroll.css'; //引入vuescroll样式
import * as echarts from 'echarts';
import VueClipboard from 'vue-clipboard2';
import VideoPlayer from 'vue-video-player';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css'; //样式必须引入
import SuperFlow from 'vue-super-flow';
import 'vue-super-flow/lib/index.css';
import '@/assets/iconfont/iconfont.css';

import VueDraggableResizable from 'vue-draggable-resizable'
Vue.component('vue-draggable-resizable', VueDraggableResizable)

//大数据可视化
import dataV from '@jiaminghi/data-view'
Vue.use(dataV)
// 设置反向代理，前端请求默认发送到 http://localhost:8443/api
const axios = require('axios');

// require('vue-video-player/node_modules/video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')
// 允许跨域携带cookie
axios.defaults.withCredentials = true;
axios.defaults.baseURL = process.env.API;

// 全局注册，之后可在其他组件中通过 this.$axios 发送数据
Vue.config.productionTip = false;
Vue.prototype.$axios = axios;
Vue.prototype.$echarts = echarts;
Vue.config.silent = true;

Vue.use(ElementUI);
Vue.use(Antd);
Vue.use(vuescroll);
Vue.use(VueClipboard);
Vue.use(VideoPlayer);
Vue.use(SuperFlow);

Vue.prototype.$getViewportSize = function(){
  return {
    width: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,//兼容性获取屏幕宽度
    height: window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight//兼容性获取屏幕高度
  };
};

router.beforeEach((to, from, next) => {
  if (to.matched.some((auth) => auth.meta.requireAuth)) {
    let token = localStorage.getItem('token');
    if (token) {
      next();
    } else {
      next({
        path: '/'
      });
    }
  } else {
    next();
  }
});


Vue.prototype.$message.config({
  duration: 2,// 持续时间
  top:`250px`, // 到页面顶部距离
  maxCount: 1 // 最大显示数, 超过限制时，最早的消息会被自动关闭
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  router,
  render: h => h(App),
});
